package com.study.filter;

import javax.servlet.http.HttpServletRequest;

import org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;

//@Component
public class PreZuulFilter extends ZuulFilter{

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public Object run() throws ZuulException {
		RequestContext context = RequestContext.getCurrentContext();
		HttpServletRequest request = context.getRequest();
		String host = request.getRemoteHost();

		System.out.println("**************PreZuulFilter-host******************** : " + host);

//		doSomething();

		return null;
	}

	private void doSomething() {
		throw new RuntimeException("*******************************:  RuntimeException");

	}

	@Override
	public String filterType() {
		return "pre";
	}

	/**
	 * 越小越先执行
	 */
	@Override
	public int filterOrder() {
		return 1;
	}

}
